﻿using System; 
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Matrix.Common.DBUtility;
using Matrix.MaKaYunShang.Model;

namespace Matrix.MaKaYunShang.DAL
{
	public partial class SysConfigDAL : BaseDAL<SysConfigDAL>
	{
        #region 默认方法
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(SysConfig model)
        {
            var strSql = new StringBuilder();
            strSql.Append("insert into SysConfig(");
            strSql.Append("IsSendRedEnvelopeToDelivery,MinRedEnvolope,MaxRedEnvolope,DayMaxRedEnvolpoe,IsPayDiscount,MinPayValueOfOrder,MaxPayValueOfOrder,DayMaxPayDiscount,IsSendCouponOnFirstSubscribe,IsSendShareRedEnvolope,MinRedEnvolopeOfShare,MaxRedEnvolopeOfShare,DayMaxCountShareRedEnvolope,MinCashWithdraw,SearchShopRadius,CashSendRedLine,UpdateTime,TimeToCancelPayOrder,TimeToFinishOrder,OrderMsgMcAlertInterval,OrderGrapTimeLength,PlatformShareAmount,ShopShareAmount,CardQuantityPerYuan,FixedQrCodeScanTime,IsOpenMall,HeadquartersCardsPercent,IsDelete");
            strSql.Append(") values (");
            strSql.Append("@IsSendRedEnvelopeToDelivery,@MinRedEnvolope,@MaxRedEnvolope,@DayMaxRedEnvolpoe,@IsPayDiscount,@MinPayValueOfOrder,@MaxPayValueOfOrder,@DayMaxPayDiscount,@IsSendCouponOnFirstSubscribe,@IsSendShareRedEnvolope,@MinRedEnvolopeOfShare,@MaxRedEnvolopeOfShare,@DayMaxCountShareRedEnvolope,@MinCashWithdraw,@SearchShopRadius,@CashSendRedLine,@UpdateTime,@TimeToCancelPayOrder,@TimeToFinishOrder,@OrderMsgMcAlertInterval,@OrderGrapTimeLength,@PlatformShareAmount,@ShopShareAmount,@CardQuantityPerYuan,@FixedQrCodeScanTime,@IsOpenMall,@HeadquartersCardsPercent,@IsDelete");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
			            new SqlParameter("@IsSendRedEnvelopeToDelivery", SqlDbType.Bit,1) ,            
                        new SqlParameter("@MinRedEnvolope", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@MaxRedEnvolope", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@DayMaxRedEnvolpoe", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@IsPayDiscount", SqlDbType.Bit,1) ,            
                        new SqlParameter("@MinPayValueOfOrder", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@MaxPayValueOfOrder", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@DayMaxPayDiscount", SqlDbType.Int,4) ,            
                        new SqlParameter("@IsSendCouponOnFirstSubscribe", SqlDbType.Bit,1) ,            
                        new SqlParameter("@IsSendShareRedEnvolope", SqlDbType.Bit,1) ,            
                        new SqlParameter("@MinRedEnvolopeOfShare", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@MaxRedEnvolopeOfShare", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@DayMaxCountShareRedEnvolope", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@MinCashWithdraw", SqlDbType.Int,4) ,            
                        new SqlParameter("@SearchShopRadius", SqlDbType.Int,4) ,            
                        new SqlParameter("@CashSendRedLine", SqlDbType.Int,4) ,            
                        new SqlParameter("@UpdateTime", SqlDbType.DateTime) ,            
                        new SqlParameter("@TimeToCancelPayOrder", SqlDbType.Int,4) ,            
                        new SqlParameter("@TimeToFinishOrder", SqlDbType.Int,4) ,            
                        new SqlParameter("@OrderMsgMcAlertInterval", SqlDbType.Int,4) ,            
                        new SqlParameter("@OrderGrapTimeLength", SqlDbType.Int,4) ,            
                        new SqlParameter("@PlatformShareAmount", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@ShopShareAmount", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@CardQuantityPerYuan", SqlDbType.Int,4) ,            
                        new SqlParameter("@FixedQrCodeScanTime", SqlDbType.Int,4) ,            
                        new SqlParameter("@IsOpenMall", SqlDbType.Bit,1) ,            
                        new SqlParameter("@HeadquartersCardsPercent", SqlDbType.Int,4) ,            
                        new SqlParameter("@IsDelete", SqlDbType.Bit,1)             
              
            };

            parameters[0].Value = model.IsSendRedEnvelopeToDelivery;
            parameters[1].Value = model.MinRedEnvolope;
            parameters[2].Value = model.MaxRedEnvolope;
            parameters[3].Value = model.DayMaxRedEnvolpoe;
            parameters[4].Value = model.IsPayDiscount;
            parameters[5].Value = model.MinPayValueOfOrder;
            parameters[6].Value = model.MaxPayValueOfOrder;
            parameters[7].Value = model.DayMaxPayDiscount;
            parameters[8].Value = model.IsSendCouponOnFirstSubscribe;
            parameters[9].Value = model.IsSendShareRedEnvolope;
            parameters[10].Value = model.MinRedEnvolopeOfShare;
            parameters[11].Value = model.MaxRedEnvolopeOfShare;
            parameters[12].Value = model.DayMaxCountShareRedEnvolope;
            parameters[13].Value = model.MinCashWithdraw;
            parameters[14].Value = model.SearchShopRadius;
            parameters[15].Value = model.CashSendRedLine;
            parameters[16].Value = model.UpdateTime;
            parameters[17].Value = model.TimeToCancelPayOrder;
            parameters[18].Value = model.TimeToFinishOrder;
            parameters[19].Value = model.OrderMsgMcAlertInterval;
            parameters[20].Value = model.OrderGrapTimeLength;
            parameters[21].Value = model.PlatformShareAmount;
            parameters[22].Value = model.ShopShareAmount;
            parameters[23].Value = model.CardQuantityPerYuan;
            parameters[24].Value = model.FixedQrCodeScanTime;
            parameters[25].Value = model.IsOpenMall;
            parameters[26].Value = model.HeadquartersCardsPercent;
            parameters[27].Value = model.IsDelete; var obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            return obj == null ? 0 : Convert.ToInt32(obj);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(SysConfig model)
        {
            var strSql = new StringBuilder();
            strSql.Append("update SysConfig set ");

            strSql.Append(" IsSendRedEnvelopeToDelivery = @IsSendRedEnvelopeToDelivery , ");
            strSql.Append(" MinRedEnvolope = @MinRedEnvolope , ");
            strSql.Append(" MaxRedEnvolope = @MaxRedEnvolope , ");
            strSql.Append(" DayMaxRedEnvolpoe = @DayMaxRedEnvolpoe , ");
            strSql.Append(" IsPayDiscount = @IsPayDiscount , ");
            strSql.Append(" MinPayValueOfOrder = @MinPayValueOfOrder , ");
            strSql.Append(" MaxPayValueOfOrder = @MaxPayValueOfOrder , ");
            strSql.Append(" DayMaxPayDiscount = @DayMaxPayDiscount , ");
            strSql.Append(" IsSendCouponOnFirstSubscribe = @IsSendCouponOnFirstSubscribe , ");
            strSql.Append(" IsSendShareRedEnvolope = @IsSendShareRedEnvolope , ");
            strSql.Append(" MinRedEnvolopeOfShare = @MinRedEnvolopeOfShare , ");
            strSql.Append(" MaxRedEnvolopeOfShare = @MaxRedEnvolopeOfShare , ");
            strSql.Append(" DayMaxCountShareRedEnvolope = @DayMaxCountShareRedEnvolope , ");
            strSql.Append(" MinCashWithdraw = @MinCashWithdraw , ");
            strSql.Append(" SearchShopRadius = @SearchShopRadius , ");
            strSql.Append(" CashSendRedLine = @CashSendRedLine , ");
            strSql.Append(" UpdateTime = @UpdateTime , ");
            strSql.Append(" TimeToCancelPayOrder = @TimeToCancelPayOrder , ");
            strSql.Append(" TimeToFinishOrder = @TimeToFinishOrder , ");
            strSql.Append(" OrderMsgMcAlertInterval = @OrderMsgMcAlertInterval , ");
            strSql.Append(" OrderGrapTimeLength = @OrderGrapTimeLength , ");
            strSql.Append(" PlatformShareAmount = @PlatformShareAmount , ");
            strSql.Append(" ShopShareAmount = @ShopShareAmount , ");
            strSql.Append(" CardQuantityPerYuan = @CardQuantityPerYuan , ");
            strSql.Append(" FixedQrCodeScanTime = @FixedQrCodeScanTime , ");
            strSql.Append(" IsOpenMall = @IsOpenMall , ");
            strSql.Append(" HeadquartersCardsPercent = @HeadquartersCardsPercent , ");
            strSql.Append(" IsDelete = @IsDelete  ");
            strSql.Append(" where Id=@Id ");

            SqlParameter[] parameters = {
			            new SqlParameter("@Id", SqlDbType.Int,4) ,            
                        new SqlParameter("@IsSendRedEnvelopeToDelivery", SqlDbType.Bit,1) ,            
                        new SqlParameter("@MinRedEnvolope", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@MaxRedEnvolope", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@DayMaxRedEnvolpoe", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@IsPayDiscount", SqlDbType.Bit,1) ,            
                        new SqlParameter("@MinPayValueOfOrder", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@MaxPayValueOfOrder", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@DayMaxPayDiscount", SqlDbType.Int,4) ,            
                        new SqlParameter("@IsSendCouponOnFirstSubscribe", SqlDbType.Bit,1) ,            
                        new SqlParameter("@IsSendShareRedEnvolope", SqlDbType.Bit,1) ,            
                        new SqlParameter("@MinRedEnvolopeOfShare", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@MaxRedEnvolopeOfShare", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@DayMaxCountShareRedEnvolope", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@MinCashWithdraw", SqlDbType.Int,4) ,            
                        new SqlParameter("@SearchShopRadius", SqlDbType.Int,4) ,            
                        new SqlParameter("@CashSendRedLine", SqlDbType.Int,4) ,            
                        new SqlParameter("@UpdateTime", SqlDbType.DateTime) ,            
                        new SqlParameter("@TimeToCancelPayOrder", SqlDbType.Int,4) ,            
                        new SqlParameter("@TimeToFinishOrder", SqlDbType.Int,4) ,            
                        new SqlParameter("@OrderMsgMcAlertInterval", SqlDbType.Int,4) ,            
                        new SqlParameter("@OrderGrapTimeLength", SqlDbType.Int,4) ,            
                        new SqlParameter("@PlatformShareAmount", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@ShopShareAmount", SqlDbType.Decimal,9) ,            
                        new SqlParameter("@CardQuantityPerYuan", SqlDbType.Int,4) ,            
                        new SqlParameter("@FixedQrCodeScanTime", SqlDbType.Int,4) ,            
                        new SqlParameter("@IsOpenMall", SqlDbType.Bit,1) ,            
                        new SqlParameter("@HeadquartersCardsPercent", SqlDbType.Int,4) ,            
                        new SqlParameter("@IsDelete", SqlDbType.Bit,1)             
              
            };

            parameters[0].Value = model.Id;
            parameters[1].Value = model.IsSendRedEnvelopeToDelivery;
            parameters[2].Value = model.MinRedEnvolope;
            parameters[3].Value = model.MaxRedEnvolope;
            parameters[4].Value = model.DayMaxRedEnvolpoe;
            parameters[5].Value = model.IsPayDiscount;
            parameters[6].Value = model.MinPayValueOfOrder;
            parameters[7].Value = model.MaxPayValueOfOrder;
            parameters[8].Value = model.DayMaxPayDiscount;
            parameters[9].Value = model.IsSendCouponOnFirstSubscribe;
            parameters[10].Value = model.IsSendShareRedEnvolope;
            parameters[11].Value = model.MinRedEnvolopeOfShare;
            parameters[12].Value = model.MaxRedEnvolopeOfShare;
            parameters[13].Value = model.DayMaxCountShareRedEnvolope;
            parameters[14].Value = model.MinCashWithdraw;
            parameters[15].Value = model.SearchShopRadius;
            parameters[16].Value = model.CashSendRedLine;
            parameters[17].Value = model.UpdateTime;
            parameters[18].Value = model.TimeToCancelPayOrder;
            parameters[19].Value = model.TimeToFinishOrder;
            parameters[20].Value = model.OrderMsgMcAlertInterval;
            parameters[21].Value = model.OrderGrapTimeLength;
            parameters[22].Value = model.PlatformShareAmount;
            parameters[23].Value = model.ShopShareAmount;
            parameters[24].Value = model.CardQuantityPerYuan;
            parameters[25].Value = model.FixedQrCodeScanTime;
            parameters[26].Value = model.IsOpenMall;
            parameters[27].Value = model.HeadquartersCardsPercent;
            parameters[28].Value = model.IsDelete; return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int Id)
        {
            var strSql = new StringBuilder();
            strSql.Append("update SysConfig set IsDelete=1 ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            return DbHelperSQL.ExecuteSql(strSql.ToString(), parameters) > 0;
        }

        /// <summary>
        /// 批量删除一批数据
        /// </summary>
        public bool DeleteList(string Idlist)
        {
            var strSql = new StringBuilder();
            strSql.Append("update SysConfig set IsDelete=1 ");
            strSql.Append(" where Id in (" + Idlist + ")  ");
            return DbHelperSQL.ExecuteSql(strSql.ToString()) > 0;
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DataSet GetModel(int Id)
        {
            var strSql = new StringBuilder();
            strSql.Append("select Id, IsSendRedEnvelopeToDelivery, MinRedEnvolope, MaxRedEnvolope, DayMaxRedEnvolpoe, IsPayDiscount, MinPayValueOfOrder, MaxPayValueOfOrder, DayMaxPayDiscount, IsSendCouponOnFirstSubscribe, IsSendShareRedEnvolope, MinRedEnvolopeOfShare, MaxRedEnvolopeOfShare, DayMaxCountShareRedEnvolope, MinCashWithdraw, SearchShopRadius, CashSendRedLine, UpdateTime, TimeToCancelPayOrder, TimeToFinishOrder, OrderMsgMcAlertInterval, OrderGrapTimeLength, PlatformShareAmount, ShopShareAmount, CardQuantityPerYuan, FixedQrCodeScanTime, IsOpenMall, HeadquartersCardsPercent, IsDelete  ");
            strSql.Append("  from SysConfig ");
            strSql.Append(" where Id=@Id  and IsDelete=0");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
			};
            parameters[0].Value = Id;

            var ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            return ds.Tables[0].Rows.Count > 0 ? ds : null;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            var strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM SysConfig where IsDelete=0 ");
            if (!string.IsNullOrEmpty(strWhere))
            {
                strSql.Append(" and " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        #endregion
		
		#region 扩展方法
		#endregion
	}
}
